package com.qianyitian.hope2.analyzer.analyzer;

import com.qianyitian.hope2.analyzer.model.KLineInfo;
import com.qianyitian.hope2.analyzer.model.ResultInfo;
import com.qianyitian.hope2.analyzer.model.Stock;
import com.qianyitian.hope2.analyzer.util.AlgorithmUtil;
import com.qianyitian.hope2.analyzer.util.Utils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

public class FarFromAverageAnalyzer extends AbstractStockAnalyzer {
    private Logger logger = LoggerFactory.getLogger(getClass());
    private double maxPrice = 10;
    private double minPrice = 0;

    public FarFromAverageAnalyzer() {
    }

    @Override
    public boolean analyze(ResultInfo resultInfo, Stock stock) {
        boolean ok = false;

        double avgCost = AlgorithmUtil.averageCostByLimitMoney(stock.getkLineInfos());
        double currentPrice = stock.getkLineInfos().get(stock.getkLineInfos().size() - 1).getClose();

        double range = Utils.calcRangeInPercentage(avgCost, currentPrice);
        if (range < 0) {
            ok = true;
            resultInfo.setValue((float) range);
        }
        return ok;
    }

    private String format(Stock stock, KLineInfo check, double times) {
        return "";
    }

    public int getWeight() {
        return 50;
    }

    @Override
    public String getDescription() {
        return "当前值远离平均值以下";
    }
}
